import React from "react";
import ReactDom from "react-dom";
import {Link} from "react-router-dom";
import '../../css/admin.css';
import {STORAGE} from "../../util/comm.jsx";
const _storage=new STORAGE();
import createHistory from 'history/createHashHistory'

class AdminHeader extends React.Component{
	constructor(){
		super();
		this.state={
			imgList:''
		}
	}
	componentDidMount(){
		this.checkUser();
	}
	checkUser(){
		let userInfo;
		if(userInfo=_storage.getStorage('ReactNews_AdminUserInfo')){
			let state=Object.assign({},userInfo,{isLogin:true});
			this.setState(state);
		}

	}
	logOut(){
		_storage.deleteStorage('ReactNews_AdminUserInfo');
		this.setState({
			isLogin:false,
			nickName:''
		})
		new createHistory().push('/');

	}
	render(){
		return(
			<div className="admin-header">
					<div className="welcome">欢迎来到新闻后台</div>
					<div className="user">
					{
						this.state.isLogin?
						<div className="logined">
							<div className="nick-name">
								<button>{this.state.nickName}</button>
							</div>
							<div className="logout">
								<button onClick={this.logOut.bind(this)}>退出</button>
							</div>
						</div>:<Link to='/login'>登录</Link>


					}
					</div>						
			</div>
		)
	}
}
export default AdminHeader;

